//
//  UIBarButtonItem+Extension.swift
//  Weibo
//
//  Created by ZhuDong on 16/5/20.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    convenience init(title: String? = nil,imageName: String? = nil,target:AnyObject?,action: Selector) {
        self.init()
        let btn = UIButton()
        
        if let imageName_check = imageName {
            
            btn.setBackgroundImage(UIImage(named: imageName_check), forState: .Normal)
            btn.setBackgroundImage(UIImage(named: imageName_check + "_highlighted"), forState: .Highlighted)
        }
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitle(title, forState: .Normal)
        btn.sizeToFit()
        self.customView = btn;
    }
}